﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Windows.Browser;
using eventr.View.Util;

namespace eventr.View
{
    public partial class RefinementPanel : UserControl
    {
        public static readonly DependencyProperty RefinersProperty;

        public RefinementPanel()
        {
            InitializeComponent();
        }

        private void RefreshPanel()
        {

            this.MainRefinementPanel.Children.Clear();

            //this is temporary code just to get data onto screen
            foreach (Model.RefinementGroup group in Refiners)
            {
                StackPanel subPanel = new StackPanel();
                TextBlock title = new TextBlock();
                title.Text = group.Name + " (" + group.RefinementValues.Count + ")";
                title.Margin = new Thickness(0, 5, 0, 0);
                title.FontSize = 14;
                title.Foreground = new SolidColorBrush(Colors.White);
                subPanel.Children.Add(title);

                foreach (Model.RefinementValue val in group.RefinementValues)
                {
                    TextBlock item = new TextBlock();
                    item.Text = val.Value;
                    item.FontSize = 12;
                    item.Margin = new Thickness(5, 0, 0, 0);
                    item.Foreground = new SolidColorBrush(Colors.White);
                    subPanel.Children.Add(item);
                }

                this.MainRefinementPanel.Children.Add(subPanel);
            }
        }

        public List<Model.RefinementGroup> Refiners
        {
            get
            {
                return GetValue(RefinersProperty) as List<Model.RefinementGroup>;
            }
            set
            {
                SetValue(RefinersProperty, value);
            }
        }


        static RefinementPanel()
        {
            RefinersProperty = DependencyProperty.Register("Refiners", typeof(List<Model.RefinementGroup>), typeof(RefinementPanel), new PropertyMetadata(null, (s, e) =>
            {
                (s as RefinementPanel).RefreshPanel();
            }));
        }
    }
}